package com.dgut.ibeacon.service.impl;

import com.dgut.ibeacon.entity.User;
import com.dgut.ibeacon.mapper.UserMapper;
import com.dgut.ibeacon.service.IUserService;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

/**
 * <p>
 *  服务实现类
 * </p>
 *
 * @author yuec
 * @since 2020-10-14
 */
@Service
public class UserServiceImpl extends ServiceImpl<UserMapper, User> implements IUserService {


    @Autowired
    UserMapper userMapper;

    @Override
    public User selectUserByLoginName(String username) {
        Map map=new HashMap();
        map.put("user_name",username);
        return  (User) userMapper.selectByMap(map).get(0);

    }

    @Override
    public boolean registerUser(User user) {
        Map map=new HashMap();
        map.put("user_name",user.getUserName());
        List list=userMapper.selectByMap(map);
        if (list.size()<=0){
            //用户名已经存在
            return false;
        }else {
            userMapper.insert(user);
        }
        return false;
    }
}
